package net.wanho.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanho.dto.SupplyExportDTO;
import net.wanho.mapper.SupplyMapper;
import net.wanho.po.Supply;
import net.wanho.service.SupplyService;
import net.wanho.vo.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 32033
 * @description 针对表【supply(供货商表)】的数据库操作Service实现
 * @createDate 2025-01-11 17:01:23
 */
@Service
public class SupplyServiceImpl extends ServiceImpl<SupplyMapper, Supply>
        implements SupplyService {

    @Override
    public PageInfo<Supply> getSupplyPage(int pageNum, int pageSize, Supply supply) {
        Page<Supply> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Supply> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(!ObjectUtils.isEmpty(supply.getSupplyNum()), Supply::getSupplyNum, supply.getSupplyNum());
        wrapper.like(!ObjectUtils.isEmpty(supply.getSupplyName()), Supply::getSupplyName, supply.getSupplyName());
        wrapper.like(!ObjectUtils.isEmpty(supply.getSupplyIntroduce()), Supply::getSupplyIntroduce, supply.getSupplyIntroduce());
        wrapper.like(!ObjectUtils.isEmpty(supply.getConcat()), Supply::getConcat, supply.getConcat());
        wrapper.like(!ObjectUtils.isEmpty(supply.getPhone()), Supply::getPhone, supply.getPhone());
        wrapper.like(!ObjectUtils.isEmpty(supply.getAddress()), Supply::getAddress, supply.getAddress());
        wrapper.like(!ObjectUtils.isEmpty(supply.getIsDelete()), Supply::getIsDelete, supply.getIsDelete());
        this.baseMapper.selectPage(page, wrapper);

        PageInfo<Supply> pageInfo = new PageInfo<>();
        pageInfo.setPageNum(page.getCurrent());
        pageInfo.setPageSize(page.getSize());
        pageInfo.setTotalNum(page.getTotal());
        pageInfo.setPageCount(page.getCurrent());
        pageInfo.setResultList(page.getRecords());
        return pageInfo;
    }

    @Override
    public Supply selectOneBySupplyNum(Integer supplyNum) {
        return this.baseMapper.selectBySupplyNum(supplyNum);
    }

    @Override
    public List<Supply> exportTable(SupplyExportDTO supplyExportDTO) {
        Page<Supply> page = new Page<>(supplyExportDTO.getPageNum(), supplyExportDTO.getPageSize());
        LambdaQueryWrapper<Supply> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(!ObjectUtils.isEmpty(supplyExportDTO.getSupplyName()), Supply::getSupplyName, supplyExportDTO.getSupplyName());
        wrapper.like(!ObjectUtils.isEmpty(supplyExportDTO.getSupplyAddress()), Supply::getAddress, supplyExportDTO.getSupplyAddress());
        wrapper.like(!ObjectUtils.isEmpty(supplyExportDTO.getConcat()), Supply::getConcat, supplyExportDTO.getConcat());
        wrapper.like(!ObjectUtils.isEmpty(supplyExportDTO.getPhone()), Supply::getPhone, supplyExportDTO.getPhone());
        this.page(page, wrapper);

        return page.getRecords();
    }
}




